package com.zfl.thread.day05;


import lombok.*;

import java.util.concurrent.atomic.AtomicReference;

public class AtomicReferenceDemo01 {

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    @ToString
    private static class User{
        String name;
        Integer age;
    }

    public static void main(String[] args) {
        User user2 = new User("zhangsan", 10);
        AtomicReference<User> ref = new AtomicReference<>(user2);
        System.out.println(ref.get());
        System.out.println(ref.getAcquire());
        User user3 = new User("lisi", 20);
        final boolean result = ref.compareAndSet(user2,user3);
        System.out.println(result);
        System.out.println(ref);
    }
}
